package com.ruoyi.project.data.config.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.data.config.domain.DsImportConfig;
import com.ruoyi.project.data.config.service.IDsImportConfigService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 数据导入配置Controller
 *
 * @author 魏刚
 * @date 2020-03-16
 */
@Controller
@RequestMapping("/data/config")
public class DsImportConfigController extends BaseController
{
    private String prefix = "data/config";

    @Autowired
    private IDsImportConfigService dsImportConfigService;

    @RequiresPermissions("data:config:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询数据导入配置列表
     */
    @RequiresPermissions("data:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DsImportConfig dsImportConfig)
    {
        startPage();
        List<DsImportConfig> list = dsImportConfigService.list(new QueryWrapper<>(dsImportConfig));
        return getDataTable(list);
    }

    /**
     * 导出数据导入配置列表
     */
    @RequiresPermissions("data:config:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DsImportConfig dsImportConfig)
    {
        List<DsImportConfig> list = dsImportConfigService.list(new QueryWrapper<>(dsImportConfig));
        ExcelUtil<DsImportConfig> util = new ExcelUtil<DsImportConfig>(DsImportConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 新增数据导入配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据导入配置
     */
    @RequiresPermissions("data:config:add")
    @Log(title = "数据导入配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DsImportConfig dsImportConfig)
    {
        return toAjax(dsImportConfigService.saveOrUpdate(dsImportConfig));
    }

    /**
     * 修改数据导入配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DsImportConfig dsImportConfig = dsImportConfigService.getById(id);
        mmap.put("dsImportConfig", dsImportConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据导入配置
     */
    @RequiresPermissions("data:config:edit")
    @Log(title = "数据导入配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DsImportConfig dsImportConfig)
    {
        return toAjax(dsImportConfigService.saveOrUpdate(dsImportConfig));
    }

    /**
     * 删除数据导入配置
     */
    @RequiresPermissions("data:config:remove")
    @Log(title = "数据导入配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dsImportConfigService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
